package cn.iocoder.yudao.module.shop.dal.mysql.crosspriceitem;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.shop.dal.dataobject.crosspriceitem.ShopCrossPriceItemDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.shop.controller.admin.crosspriceitem.vo.*;

/**
 * 跨店铺项目对应 Mapper
 *
 * @author 曹建伟
 */
@Mapper
public interface ShopCrossPriceItemMapper extends BaseMapperX<ShopCrossPriceItemDO> {

    default PageResult<ShopCrossPriceItemDO> selectPage(ShopCrossPriceItemPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ShopCrossPriceItemDO>()
                .eqIfPresent(ShopCrossPriceItemDO::getSourceItemId, reqVO.getSourceItemId())
                .eqIfPresent(ShopCrossPriceItemDO::getTargetTenantId, reqVO.getTargetTenantId())
                .eqIfPresent(ShopCrossPriceItemDO::getTargetItemId, reqVO.getTargetItemId())
                .betweenIfPresent(ShopCrossPriceItemDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ShopCrossPriceItemDO::getId));
    }

    default List<ShopCrossPriceItemDO> selectList(ShopCrossPriceItemExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ShopCrossPriceItemDO>()
                .eqIfPresent(ShopCrossPriceItemDO::getSourceItemId, reqVO.getSourceItemId())
                .eqIfPresent(ShopCrossPriceItemDO::getTargetTenantId, reqVO.getTargetTenantId())
                .eqIfPresent(ShopCrossPriceItemDO::getTargetItemId, reqVO.getTargetItemId())
                .betweenIfPresent(ShopCrossPriceItemDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ShopCrossPriceItemDO::getId));
    }

    default ShopCrossPriceItemDO selectByTenantId(Long sourceTenantId, Long sourceItemId, Long targetTenantId){
        return selectOne(new LambdaQueryWrapperX<ShopCrossPriceItemDO>()
                .eq(ShopCrossPriceItemDO::getTenantId, sourceTenantId)
                .eq(ShopCrossPriceItemDO::getSourceItemId, sourceItemId)
                .eq(ShopCrossPriceItemDO::getTargetTenantId, targetTenantId));
    }

}
